<template>
  <k-form-modal title="更新备注" v-bind="formModalState" v-on="formModalEvent">
    <el-form-item label="备注" prop="name">
      <el-input v-model="state.model.remark" type="textarea" :rows="4" placeholder="请输入备注" />
    </el-form-item>
  </k-form-modal>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useFormModal } from '@crud/index';
import { updateCustomerRemark } from '@/api/crm-kgj/user';
import { ElMessage } from 'element-plus';
defineOptions({ name: 'MajorCustomerEditModal' });

const formRef = ref();
const emits = defineEmits(['after-submit']);
const { state, formModalState, formModalEvent, ...methods } = useFormModal({
  formRef,
  model: {
    remark: ''
  },
  getParams: (mdoel) => mdoel,
  onShow: (mode = 0, data: any) => {
    if (mode === 0) {
      methods.resetModel();
    } else if (data) {
      state.model = {
        remark: data.remark,
        id: data.id
      };
    }
  },
  onSubmit: async (model, mode = 0) => {
    const res = await updateCustomerRemark(model);
    if (!res.err) {
      ElMessage.success('更新成功');
      emits('after-submit');
    }
    return res;
  }
});
defineExpose({
  show: methods.show
});
</script>
